package com.etc.controller;


import com.etc.entity.Concern;
import com.etc.entity.Gift;
import com.etc.entity.History;
import com.etc.service.FocusService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("focus")
public class FocusController {

    @Autowired
    FocusService service;

    /**
     * 跳转后台分类界面
     * @return
     */
    @RequestMapping("concern")
    public String concern(){
        return "concern/concernPage";
    }
    /**
     * 跳转后台分类界面
     * @return
     */
    @RequestMapping("history")
    public String history(){
        return "history/historyPage";
    }
    
    /**
     * 添加历史记录
     * @param userId
     * @param roomId
     * @param videoId
     * @return
     */
    @RequestMapping("addHistory")
    @ResponseBody
    public boolean addHistory(@RequestParam("userId") String userId,
                              @RequestParam(value = "roomId",defaultValue = "")String roomId,
                              @RequestParam(value = "videoId",defaultValue = "")String videoId){
        return service.addHistory(userId, roomId, videoId);
    }

    /**
     * 查询是否关注
     * @param userId
     * @param roomId
     * @return
     */
    @RequestMapping("getConcern")
    @ResponseBody
    public boolean getConcern(@RequestParam("userId") String userId,
                              @RequestParam(value = "roomId",defaultValue = "")String roomId){
        return service.queryConcernByUserIdAndRoomId(userId, roomId);
    }

    /**
     * 添加关注
     * @param userId
     * @param roomId
     * @return
     */
    @RequestMapping("addConcern")
    @ResponseBody
    public boolean addConcern(@RequestParam("userId") String userId,
                              @RequestParam(value = "roomId",defaultValue = "")String roomId){
        return service.addConcern(userId, roomId);
    }

    /**
     * 取消关注
     * @param userId
     * @param roomId
     * @return
     */
    @RequestMapping("delConcern")
    @ResponseBody
    public boolean delConcern(@RequestParam("userId") String userId,
                              @RequestParam(value = "roomId",defaultValue = "")String roomId){
        return service.deleteConcernById(userId, roomId);
    }

    /**
     * 关注分页
     * @return
     */
    @RequestMapping("getConcernPage")
    @ResponseBody
    public PageInfo<Concern> getConcernPage(
            @RequestParam(value = "userId",defaultValue = "")String userId
            ,@RequestParam(value = "pageNo",defaultValue = "1")int pageNo
            ,@RequestParam(value = "pageSize",defaultValue = "15")int pageSize){
        PageInfo<Concern> concernList = service.getConcernList(userId,pageNo, pageSize);
        return concernList;
    }
    
    
    /**
     * 历史记录分页
     * @return
     */
    @RequestMapping("getHistoryPage")
    @ResponseBody
    public PageInfo<History> getHistoryPage(
            @RequestParam(value = "userId",defaultValue = "")String userId
            ,@RequestParam(value = "pageNo",defaultValue = "1")int pageNo
            ,@RequestParam(value = "pageSize",defaultValue = "15")int pageSize){
        PageInfo<History> historyList = service.getHistoryList(userId,pageNo, pageSize);
        return historyList;
    }

}
